﻿using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml;

namespace YJKBatchPrinter.Utils
{
	public class FormDataIni
	{
		public FormDataIni(string sFullPath)
		{
			this.m_sIniFullPath = sFullPath;
		}

		[DllImport("kernel32")]
		private static extern int GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);

		[DllImport("kernel32")]
		private static extern long WritePrivateProfileString(string mpAppName, string mpKeyName, string mpKeyValue, string mpFileName);

		public string ReadData(string sArea, string sKey, string sDef = "")
		{
			StringBuilder stringBuilder = new StringBuilder(1024);
			FormDataIni.GetPrivateProfileString(sArea, sKey, sDef, stringBuilder, 1024, this.m_sIniFullPath);
			return stringBuilder.ToString();
		}

		public void WriteData(string sArea, string sKey, string sValue)
		{
			FormDataIni.WritePrivateProfileString(sArea, sKey, sValue, this.m_sIniFullPath);
		}

		private string m_sIniFullPath;

		private XmlDocument m_xmlDoc = new XmlDocument();

		public const string sSegName = "UIData";
	}
}
